<?php

namespace app\api\model;

use think\Model;

class Createclass extends Model
{   

    protected $table = 't_av_room';


    // 根据房间id获取课件号--PC接口
    public function Index($id)
    {   
        $info = $this->where('id',$id)->value('tid');
    
        $data = Db('teaching_material')->where('id','in',$info)->field('id,name,url')->select();

        foreach($data as $k => $v){
            $res = json_decode($v['url']);
            $data[$k]['url'] = $res[0];
        }
        return $data;
    }


    // 上传课前文档 -- 阿卡索接口
    public function uploaddoc($data)
    {
        $res = [
            'file_id' => Db('teaching_material')->insertGetId($data),
        ];
        return $res;
    }

    // 上传课前文档绑定课前文档到预约教室
    public function uploadClass($data)
    {
        $res = $this->where('id',$data['id'])->update(['typeid'=>$data['typeid']]);
        if($res){
            return Db('teaching_material')->where('id','in',$data['typeid'])->field('id as file_id, name as filetitle, status as file_status')->select();
        }
            
        return ;
    }

    // 解除课前文档与预约教室的绑定
    public function deleteClass($data)
    {
        $res = $this->where('id','in',$data['id'])->delete();
        if($res){
            return Db('teaching_material')->where('id','in',$data['typeid'])->field('id as file_id, name as filetitle, status as file_status')->select();
        }
            
        return ;
    }
}